From: Simon Sapin Date: Wed, 2 Mar 2016 15:37:44 +0000 (+0100) Subject: Update to rust-url 1.x X-Git-Tag: archive/raspbian/0.35.0-2+rpi1~3^2^2^2^2^2^2^2~22^2~14^2~29^2 X-Git-Url: https://dgit.raspbian.org/%22http://www.example.com/cgi/success//%22http:/www.example.com/cgi/success/?a=commitdiff_plain;h=32562e9288ea0efcdf92f1e58d456feef8179552;p=cargo.git Update to rust-url 1.x --- diff --git a/Cargo.lock b/Cargo.lock index f10d66682..141402459 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6,19 +6,19 @@ dependencies = [ "bufstream 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "crates-io 0.2.0", "crossbeam 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", - "curl 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)", + "curl 0.2.19 (registry+https://github.com/rust-lang/crates.io-index)", "docopt 0.6.78 (registry+https://github.com/rust-lang/crates.io-index)", "env_logger 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "filetime 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", "flate2 0.2.13 (registry+https://github.com/rust-lang/crates.io-index)", "fs2 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", - "git2 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", - "git2-curl 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "git2 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", + "git2-curl 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", "glob 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", "hamcrest 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "kernel32-sys 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", - "libgit2-sys 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", + "libgit2-sys 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", "num_cpus 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", "regex 0.1.58 (registry+https://github.com/rust-lang/crates.io-index)", @@ -29,7 +29,7 @@ dependencies = [ "term 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)", "time 0.1.34 (registry+https://github.com/rust-lang/crates.io-index)", "toml 0.1.28 (registry+https://github.com/rust-lang/crates.io-index)", - "url 0.2.38 (registry+https://github.com/rust-lang/crates.io-index)", + "url 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -72,9 +72,9 @@ dependencies = [ name = "crates-io" version = "0.2.0" dependencies = [ - "curl 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)", + "curl 0.2.19 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-serialize 0.3.18 (registry+https://github.com/rust-lang/crates.io-index)", - "url 0.2.38 (registry+https://github.com/rust-lang/crates.io-index)", + "url 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -84,14 +84,14 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "curl" -version = "0.2.18" +version = "0.2.19" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "curl-sys 0.1.34 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", "openssl-sys 0.7.8 (registry+https://github.com/rust-lang/crates.io-index)", - "url 0.5.7 (registry+https://github.com/rust-lang/crates.io-index)", + "url 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -167,24 +167,24 @@ dependencies = [ [[package]] name = "git2" -version = "0.4.2" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "bitflags 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", - "libgit2-sys 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", - "url 0.5.7 (registry+https://github.com/rust-lang/crates.io-index)", + "libgit2-sys 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", + "url 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "git2-curl" -version = "0.4.0" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "curl 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)", - "git2 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", + "curl 0.2.19 (registry+https://github.com/rust-lang/crates.io-index)", + "git2 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", - "url 0.5.7 (registry+https://github.com/rust-lang/crates.io-index)", + "url 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -200,6 +200,16 @@ dependencies = [ "num 0.1.31 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "idna" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "matches 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "unicode-bidi 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", + "unicode-normalization 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "kernel32-sys" version = "0.2.1" @@ -216,7 +226,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "libgit2-sys" -version = "0.4.2" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "cmake 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)", @@ -436,24 +446,11 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "url" -version = "0.2.38" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ + "idna 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "matches 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc-serialize 0.3.18 (registry+https://github.com/rust-lang/crates.io-index)", - "uuid 0.1.18 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "url" -version = "0.5.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "matches 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc-serialize 0.3.18 (registry+https://github.com/rust-lang/crates.io-index)", - "unicode-bidi 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", - "unicode-normalization 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", - "uuid 0.1.18 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -470,15 +467,6 @@ name = "utf8-ranges" version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -[[package]] -name = "uuid" -version = "0.1.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "rand 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc-serialize 0.3.18 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "winapi" version = "0.2.6" diff --git a/Cargo.toml b/Cargo.toml index b522909ad..a5d673869 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -42,7 +42,7 @@ tempdir = "0.3" term = "0.4.4" time = "0.1" toml = "0.1" -url = "0.2" +url = "1.1" winapi = "0.2" [dev-dependencies] diff --git a/src/cargo/core/package_id_spec.rs b/src/cargo/core/package_id_spec.rs index 1621ccfc2..a643713b2 100644 --- a/src/cargo/core/package_id_spec.rs +++ b/src/cargo/core/package_id_spec.rs @@ -2,7 +2,7 @@ use std::collections::HashMap; use std::fmt; use semver::Version; -use url::{self, Url, UrlParser}; +use url::Url; use core::PackageId; use util::{CargoResult, ToUrl, human, ToSemver, ChainError}; @@ -22,7 +22,7 @@ impl PackageIdSpec { Err(..) => {} } if !spec.contains("://") { - match url(&format!("cargo://{}", spec)) { + match Url::parse(&format!("cargo://{}", spec)) { Ok(url) => return PackageIdSpec::from_url(url), Err(..) => {} } @@ -64,15 +64,16 @@ impl PackageIdSpec { } fn from_url(mut url: Url) -> CargoResult { - if url.query.is_some() { + if url.query().is_some() { bail!("cannot have a query string in a pkgid: {}", url) } - let frag = url.fragment.take(); + let frag = url.fragment().map(|s| s.to_owned()); + url.set_fragment(None); let (name, version) = { - let path = try!(url.path().chain_error(|| { + let mut path = try!(url.path_segments().chain_error(|| { human(format!("pkgid urls must have a path: {}", url)) })); - let path_name = try!(path.last().chain_error(|| { + let path_name = try!(path.next_back().chain_error(|| { human(format!("pkgid urls must have at least one path \ component: {}", url)) })); @@ -171,31 +172,17 @@ impl PackageIdSpec { } } -fn url(s: &str) -> url::ParseResult { - return UrlParser::new().scheme_type_mapper(mapper).parse(s); - - fn mapper(scheme: &str) -> url::SchemeType { - if scheme == "cargo" { - url::SchemeType::Relative(1) - } else { - url::whatwg_scheme_type_mapper(scheme) - } - } - -} - impl fmt::Display for PackageIdSpec { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { let mut printed_name = false; match self.url { Some(ref url) => { - if url.scheme == "cargo" { - try!(write!(f, "{}/{}", url.host().unwrap(), - url.path().unwrap().join("/"))); + if url.scheme() == "cargo" { + try!(write!(f, "{}{}", url.host().unwrap(), url.path())); } else { try!(write!(f, "{}", url)); } - if url.path().unwrap().last().unwrap() != &self.name { + if url.path_segments().unwrap().next_back().unwrap() != &self.name { printed_name = true; try!(write!(f, "#{}", self.name)); } @@ -215,7 +202,7 @@ impl fmt::Display for PackageIdSpec { #[cfg(test)] mod tests { use core::{PackageId, SourceId}; - use super::{PackageIdSpec, url}; + use super::PackageIdSpec; use url::Url; use semver::Version; @@ -230,32 +217,32 @@ mod tests { ok("http://crates.io/foo#1.2.3", PackageIdSpec { name: "foo".to_string(), version: Some(Version::parse("1.2.3").unwrap()), - url: Some(url("http://crates.io/foo").unwrap()), + url: Some(Url::parse("http://crates.io/foo").unwrap()), }); ok("http://crates.io/foo#bar:1.2.3", PackageIdSpec { name: "bar".to_string(), version: Some(Version::parse("1.2.3").unwrap()), - url: Some(url("http://crates.io/foo").unwrap()), + url: Some(Url::parse("http://crates.io/foo").unwrap()), }); ok("crates.io/foo", PackageIdSpec { name: "foo".to_string(), version: None, - url: Some(url("cargo://crates.io/foo").unwrap()), + url: Some(Url::parse("cargo://crates.io/foo").unwrap()), }); ok("crates.io/foo#1.2.3", PackageIdSpec { name: "foo".to_string(), version: Some(Version::parse("1.2.3").unwrap()), - url: Some(url("cargo://crates.io/foo").unwrap()), + url: Some(Url::parse("cargo://crates.io/foo").unwrap()), }); ok("crates.io/foo#bar", PackageIdSpec { name: "bar".to_string(), version: None, - url: Some(url("cargo://crates.io/foo").unwrap()), + url: Some(Url::parse("cargo://crates.io/foo").unwrap()), }); ok("crates.io/foo#bar:1.2.3", PackageIdSpec { name: "bar".to_string(), version: Some(Version::parse("1.2.3").unwrap()), - url: Some(url("cargo://crates.io/foo").unwrap()), + url: Some(Url::parse("cargo://crates.io/foo").unwrap()), }); ok("foo", PackageIdSpec { name: "foo".to_string(), diff --git a/src/cargo/core/source.rs b/src/cargo/core/source.rs index c1b6dd315..2229c33bb 100644 --- a/src/cargo/core/source.rs +++ b/src/cargo/core/source.rs @@ -2,7 +2,6 @@ use std::cmp::{self, Ordering}; use std::collections::hash_map::{HashMap, Values, IterMut}; use std::fmt::{self, Formatter}; use std::hash; -use std::mem; use std::path::Path; use std::sync::Arc; use rustc_serialize::{Decodable, Decoder, Encodable, Encoder}; @@ -101,20 +100,20 @@ impl SourceId { "git" => { let mut url = url.to_url().unwrap(); let mut reference = GitReference::Branch("master".to_string()); - let pairs = url.query_pairs().unwrap_or(Vec::new()); - for &(ref k, ref v) in pairs.iter() { + for (k, v) in url.query_pairs() { match &k[..] { // map older 'ref' to branch "branch" | - "ref" => reference = GitReference::Branch(v.clone()), + "ref" => reference = GitReference::Branch(v.into_owned()), - "rev" => reference = GitReference::Rev(v.clone()), - "tag" => reference = GitReference::Tag(v.clone()), + "rev" => reference = GitReference::Rev(v.into_owned()), + "tag" => reference = GitReference::Tag(v.into_owned()), _ => {} } } - url.query = None; - let precise = mem::replace(&mut url.fragment, None); + let precise = url.fragment().map(|s| s.to_owned()); + url.set_fragment(None); + url.set_query(None); SourceId::for_git(&url, reference).with_precise(precise) } "registry" => { diff --git a/src/cargo/sources/git/source.rs b/src/cargo/sources/git/source.rs index 1ac3f183f..b47dda80a 100644 --- a/src/cargo/sources/git/source.rs +++ b/src/cargo/sources/git/source.rs @@ -1,8 +1,7 @@ use std::fmt::{self, Debug, Formatter}; use std::hash::{Hash, Hasher, SipHasher}; -use std::mem; -use url::{self, Url}; +use url::Url; use core::source::{Source, SourceId}; use core::GitReference; @@ -62,15 +61,11 @@ impl<'cfg> GitSource<'cfg> { fn ident(url: &Url) -> String { let mut hasher = SipHasher::new_with_keys(0,0); - // FIXME: this really should be able to not use to_str() everywhere, but the - // compiler seems to currently ask for static lifetimes spuriously. - // Perhaps related to rust-lang/rust#15144 let url = canonicalize_url(url); - let ident = url.path().unwrap_or(&[]) - .last().map(|a| a.clone()).unwrap_or(String::new()); + let ident = url.path_segments().and_then(|mut s| s.next_back()).unwrap_or(""); let ident = if ident == "" { - "_empty".to_string() + "_empty" } else { ident }; @@ -84,39 +79,27 @@ pub fn canonicalize_url(url: &Url) -> Url { let mut url = url.clone(); // Strip a trailing slash - if let url::SchemeData::Relative(ref mut rel) = url.scheme_data { - if rel.path.last().map(|s| s.is_empty()).unwrap_or(false) { - rel.path.pop(); - } - } + url.path_segments_mut().unwrap().pop_if_empty(); // HACKHACK: For github URL's specifically just lowercase // everything. GitHub treats both the same, but they hash // differently, and we're gonna be hashing them. This wants a more // general solution, and also we're almost certainly not using the // same case conversion rules that GitHub does. (#84) - if url.domain() == Some("github.com") { - url.scheme = "https".to_string(); - if let url::SchemeData::Relative(ref mut rel) = url.scheme_data { - rel.port = Some(443); - rel.default_port = Some(443); - let path = mem::replace(&mut rel.path, Vec::new()); - rel.path = path.into_iter().map(|s| { - s.chars().flat_map(|c| c.to_lowercase()).collect() - }).collect(); - } + if url.host_str() == Some("github.com") { + url.set_scheme("https").unwrap(); + let path = url.path().to_lowercase(); + url.set_path(&path); } // Repos generally can be accessed with or w/o '.git' - if let url::SchemeData::Relative(ref mut rel) = url.scheme_data { - let needs_chopping = { - let last = rel.path.last().map(|s| &s[..]).unwrap_or(""); - last.ends_with(".git") + let needs_chopping = url.path().ends_with(".git"); + if needs_chopping { + let last = { + let last = url.path_segments().unwrap().next_back().unwrap(); + last[..last.len() - 4].to_owned() }; - if needs_chopping { - let last = rel.path.pop().unwrap(); - rel.path.push(last[..last.len() - 4].to_string()) - } + url.path_segments_mut().unwrap().pop().push(&last); } url diff --git a/src/cargo/sources/registry.rs b/src/cargo/sources/registry.rs index 9652d8145..c1695da6b 100644 --- a/src/cargo/sources/registry.rs +++ b/src/cargo/sources/registry.rs @@ -231,7 +231,7 @@ impl<'cfg> RegistrySource<'cfg> { pub fn new(source_id: &SourceId, config: &'cfg Config) -> RegistrySource<'cfg> { let hash = hex::short_hash(source_id); - let ident = source_id.url().host().unwrap().to_string(); + let ident = source_id.url().host_str().unwrap_or("").to_string(); let part = format!("{}-{}", ident, hash); RegistrySource { checkout_path: config.registry_index_path().join(&part), @@ -558,9 +558,10 @@ impl<'cfg> Source for RegistrySource<'cfg> { let config = try!(self.config()); let url = try!(config.dl.to_url().map_err(internal)); let mut url = url.clone(); - url.path_mut().unwrap().push(package.name().to_string()); - url.path_mut().unwrap().push(package.version().to_string()); - url.path_mut().unwrap().push("download".to_string()); + url.path_segments_mut().unwrap() + .push(package.name()) + .push(&package.version().to_string()) + .push("download"); let krate = try!(self.download_package(package, &url).chain_error(|| { internal(format!("failed to download package `{}` from {}", package, url)) diff --git a/src/cargo/util/to_url.rs b/src/cargo/util/to_url.rs index 2e3365cb2..59159cc1d 100644 --- a/src/cargo/util/to_url.rs +++ b/src/cargo/util/to_url.rs @@ -1,4 +1,4 @@ -use url::{self, Url, UrlParser}; +use url::Url; use std::path::Path; pub trait ToUrl { @@ -19,7 +19,7 @@ impl<'a> ToUrl for &'a Url { impl<'a> ToUrl for &'a str { fn to_url(self) -> Result { - UrlParser::new().scheme_type_mapper(mapper).parse(self).map_err(|s| { + Url::parse(self).map_err(|s| { format!("invalid url `{}`: {}", self, s) }) } @@ -32,11 +32,3 @@ impl<'a> ToUrl for &'a Path { }) } } - -fn mapper(s: &str) -> url::SchemeType { - match s { - "git" => url::SchemeType::Relative(9418), - "ssh" => url::SchemeType::Relative(22), - s => url::whatwg_scheme_type_mapper(s), - } -} diff --git a/src/crates-io/Cargo.toml b/src/crates-io/Cargo.toml index e049066f8..72f732295 100644 --- a/src/crates-io/Cargo.toml +++ b/src/crates-io/Cargo.toml @@ -14,5 +14,5 @@ path = "lib.rs" [dependencies] curl = "0.2" -url = "0.2" +url = "1.0" rustc-serialize = "0.3"